package lagou.homework.lagou_homework_rocketmq.repository;

import lagou.homework.lagou_homework_rocketmq.entity.Order;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
public interface OrderRepository extends JpaRepository<Order,String> {

    /**
     * 根据订单号查询订单
     * @param orderNo
     * @return
     */
    public Order findByOrderNo(String orderNo);

    /**
     * 更新订单状态
     * @param orderNo
     * @param status
     */
    @Query(nativeQuery = true,value = "update orderInfo set status = :status where orderNo = :orderNo")
    @Modifying
    @Transactional
    public void updateOrderStatus(@Param("orderNo") String orderNo, @Param("status") int status);

    public Order findBySeckillIdAndUserId(String seckillId,String userId);
}
